//导入模块
import { load, isLogin } from "/code/admin/util/LoadView.js"
load("homePage")
let user = JSON.parse(isLogin())
//渲染用户基本信息
document.querySelector(".userInfo").innerHTML = `
    <img src="${user.photo}" style="width:100px;height:100px;border-radius:50%;">
    <div>
        <div>${user.username}</div>
        <div><pre>${user.instruction || "这个人很懒"}</pre></div>
    </div>
`
async function abc() {
  let dianxinganli = 0
  let zuixindongtai = 0
  let tongzhigonggao = 0
  let res = await fetch(`http://localhost:3000/news?author=${user.username}`).then(res => res.json())
  for (let i = 0; i < res.length; i++) {
    // let arr = []
    // for (let j = 0; j < 3:j++) {
    //   arr.push({
    //     name:.
    //     value:
    //   })
    // }
    if (res[i].type == "典型案例") {
      dianxinganli++
    } else if (res[i].type == "通知公告") {
      tongzhigonggao++
    } else if (res[i].type == "最新动态") {
      zuixindongtai++
    }
    

  }
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById('main'));
  // 指定图表的配置项和数据
  var option = {
    title: {
      text: '用户发布的新闻信息',
      subtext: '不同类型的占比',
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: '60%',
        data: [
          { value: dianxinganli, name: '典型案例' },
          { value: tongzhigonggao, name: '通知公告' },
          { value: zuixindongtai, name: '最新动态' }
        ],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  };

  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}
abc()
